<?php

/*
 * This file is part of the yuki package.
 * Copyright (c) 2011 olamedia <olamedia@gmail.com>
 *
 * This source code is release under the MIT License.
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * yRectangle
 *
 * @package yuki
 * @subpackage geometry
 * @version SVN: $Id: yRectangle.php 145 2011-02-20 04:22:41Z olamedia@gmail.com $
 * @revision SVN: $Revision: 145 $
 * @date $Date: 2011-02-20 04:22:41 +0000 (Sun, 20 Feb 2011) $
 * @author olamedia
 * @license http://www.opensource.org/licenses/mit-license.php MIT
 */
class yRectangle{
    /**
     * Upper-left corner of the rectangle.
     * @var yPoint
     */
    protected $_location = null;
    /**
     * Dimension of the rectangle.
     * @var yDimension
     */
    protected $_size = null;
    /**
     * Constructor.
     */
    public function __construct(){
        $this->_location = new yPoint();
        $this->_size = new yDimension();
    }
    /**
     * @return yRectangle
     */
    public function getBounds(){
        return $this;
    }
    /**
     * Sets location of rectangle.
     * setSize(int $x, int $y)
     * setSize(yPoint $point)
     * @return yRectangle 
     */
    public function setLocation(){
        if (func_num_args() == 1){
            $rectangle = func_get_arg(0);
            $this->_location->setX($rectangle->getLocation()->getX());
            $this->_location->setY($rectangle->getLocation()->getY());
        }elseif (func_num_args() == 2){
            $args = func_get_args();
            $this->_location->setX($args[0]);
            $this->_location->setY($args[1]);
        }
        return $this;
    }
    /**
     * Gets rectangle location.
     * @return yPoint
     */
    public function getLocation(){
        return $this->_location;
    }
    /**
     * Sets size of rectangle.
     * setSize(int $width, int $height)
     * setSize(yDimension $dimension)
     * @return yRectangle 
     */
    public function setSize(){
        if (func_num_args() == 1){
            $dimension = func_get_arg(0);
            $this->_size->setWidth($dimension->getWidth());
            $this->_size->setHeight($dimension->getHeight());
        }elseif (func_num_args() == 2){
            $args = func_get_args();
            $this->_size->setWidth($args[0]);
            $this->_size->setHeight($args[1]);
        }
        return $this;
    }
    /**
     * Gets size of rectangle.
     * @return yDimension
     */
    public function getSize(){
        return $this->_size;
    }
    /**
     * Translates this rectangle location.
     * By dx along the x axis and dy along the y axis,
     * so that it now represents the point (x+dx,y+dy).
     * @param int $dx
     * @param int $dy
     * @return yRectangle 
     */
    public function translate($dx, $dy){
        $this->_location->translate($dx, $dy);
        return $this;
    }
}

